package net.pulseproject.commons.midi.mediator;

import net.pulseproject.commons.midi.entity.MidiSocket;
import net.pulseproject.commons.misc.collection.EnablerCollection;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class EnablerCollectionWrapperImpl implements EnablerCollectionWrapper {
	
	private static final Log LOG = LogFactory.getLog(EnablerCollectionWrapperImpl.class);
	
	private EnablerCollection<MidiSocket, ReroutingListener> enablerCollection;
	
	
	public final void setEnablerCollection(final EnablerCollection<MidiSocket, ReroutingListener> enablerCollection) {
		LOG.debug("setEnablerCollection(enablerCollection)");
		if(enablerCollection == null) { throw new IllegalArgumentException("enablerCollection == null"); }
		// TODO is it really okay to just reset the underlying enablerCollection?
		this.enablerCollection = enablerCollection;
	}
	

	@Override
	public final boolean isEnabledFor(final MidiSocket value) {
		if(this.enablerCollection == null) {
			throw new RuntimeException("enablerCollection not yet set! (most likely no routing activated)");
		}
		
		return this.enablerCollection.isEnabledFor(value);
	}

	@Override
	public final void setEnabledFor(final MidiSocket value, final boolean enabled) {
		if(this.enablerCollection == null) {
			throw new RuntimeException("enablerCollection not yet set! (most likely no routing activated)");
		}
		
		this.enablerCollection.setEnabledFor(value, enabled);
	}

	@Override
	public final void setAllDisabledExcept(final MidiSocket value) {
		this.enablerCollection.setAllDisabledExcept(value);
	}

	@Override
	public final void setAllEnabled() {
		this.enablerCollection.setAllEnabled();
	}

}
